package com.smit.utils;

import java.util.Locale;

public class StrUtil {

    public static String getFileSizeStr(long size) {
        float fsize = size;
        float g = fsize / 1024 / 1024 / 1024;
        float m = fsize / 1024 / 1024;
        float k = fsize / 1024;
        float b = fsize;
        String sizeStr = "0B";
        if (g > 1) {
            sizeStr = String.format(Locale.getDefault(), "%.2f", g) + "GB";
        } else if (m > 1) {
            sizeStr = String.format(Locale.getDefault(), "%.2f", m) + "MB";
        } else if (k > 1) {
            sizeStr = String.format(Locale.getDefault(), "%.2f", k) + "KB";
        } else {
            sizeStr = String.format(Locale.getDefault(), "%.2f", b) + "B";
        }
        return sizeStr;
    }

    private StrUtil() {

    }
}